import http from './http'

interface UserVO {
  userId: number
  username: string
  name: string
  roleList: string[]
}

interface ApiResponse<T> {
  code: number
  data: T
  msg?: string
}

//user
// 用户登录
export const login = (data: { username: string; password: string }) => {
  return http.post('/login', data)
}
//退出登录
export const logout = () => {
  return http.post('/logout')
}
// 注册用户
export const register = (data: { name:string;username: string; password: string }) => {
  return http.post('/register', data)
}
// 获取用户信息
export const getUserInfo = () => {
  return http.get<ApiResponse<UserVO>>('/users')
}
//admin
// 删除用户
export const deleteUser = (userId: number) => {
  return http.delete(`/users/${userId}`)
}
// 全部查询用户
export const queryAllUsers = () => {
  return http.get(`/users/all`)
}
// 新增用户
export const addUser = (data: { username: string; password: string ;}) => {
  return http.post('/users', data)
}
// 修改用户
export const updateUser = (data: { username: string; password: string ;}) => {
  return http.put('/users', data)
}

